<template>
  <div align="center">
    <h1 style="font-size:30px">注册</h1>
    <p>姓名：<input type="text" v-model="form.name"></p>
    <p>用户名：<input type="text" v-model="form.username"></p>
    <p>密码：<input type="text" v-model="form.password"></p>
    <button @click="add_tea">注册</button>
    <router-link :to="{name:'logintea'}">登录</router-link>
    <h1 style="font-size: 30px">老师</h1>
    <table>
      <tr>
        <td>老师</td>
        <td>用户名</td>
      </tr>
      <tr v-for="i in teas">
        <td>{{ i.name }}</td>
        <td>{{ i.username }}</td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  name: "addtea",
  data() {
    return {
      form: {},
      teas: []
    }
  },
  methods: {
    add_tea() {
      this.$axios.post('tea/', this.form)
        .then(res => {
          if (res.data.code == 200) {
            alert('注册成功')
            this.form = {}
            this.get_tea()

          }
        })

    },
    get_tea() {
      this.$axios.get('tea/')
        .then(res => {
          if (res.data.code == 200) {
            this.teas = res.data.list
          }
        })
    }
  },
  mounted() {
    this.get_tea()
  }
}
</script>

<style scoped>

</style>
